<?php 

	Class ContentAction extends CommonAction{

		public function index(){
			$this->redirect('Content/system');
		}

		public function contentList(){
			$display = I('d',0,'intval');
			if(!$display){
				$this->assign('URL',U('Admin/Content/contentList',array('d' => 1)))->display('index');
			}else{
				$count = M('content')->count();
				$this->contentcount = $count;
				$content = M('content')->order('id desc')->select();
				$this->typename = gettypename();
				$this->assign('list',$content)->display();
			}
		}

		public function addContent(){
			$t = M('setting')->find();
			$this->assign('t',$t)->display();
		}

		public function addContentHandle(){
			if(IS_POST){
				$result = M('content')->data($_POST)->add();
				if(result){
					$this->success("发布文章成功!");
				}else{
					$this->error("发布文章失败!");
				}
			}
		}

		public function deleteContentHandle(){
			$id = I('id',-1,'intval');
			if($result = M('content')->where(array('id'=>$id))->delete()){
				$this->success('删除成功！');
			}else{
				$this->error('删除失败！');
			}
		}

		public function system(){
			$setting = M('setting')->find();
			$this->assign('setting',$setting)->display();
		}

		public function settingHandle(){
			if(IS_POST){
				$_POST['id'] = 1;
				$result = M('setting')->data($_POST)->save();
				if($result){
					$this->success('保存更新完成！');
				}else{
					$this->error('保存失败！');
				}
			}
		}

		public function savecontent(){
			$id = I('id',0,'intval');
			$content = M('content')->where(array('id'=>$id))->find();
			$this->assign('c',$content)->display();
		}

		
		public function saveContentHandle(){
			if(IS_POST){
				$result = M('content')->data($_POST)->save();
				if($result){
					$this->success('保存更新完成！');
				}else{
					$this->error('保存失败！');
				}
			}

		}
	}
 ?>